﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace Eksponent.RazorRocks.Helpers
{
    static class RequestScoped
    {
        public static T Get<T>(string key, Func<T> defaultValue)
        {
            T val;
            if( HttpContext.Current.Items.Contains(key) )
            {
                val = (T) HttpContext.Current.Items[key];
            } else
            {
                val = Set(key, defaultValue());
            }
            return val;
        }

        public static T Set<T>(string key, T value)
        {
            HttpContext.Current.Items[key] = value;
            return value;
        }

    }
}
